<?php
namespace app\common\model;

use think\Model;

class Detail extends Model
{
    //默认主键
    protected $pk = 'detail_id';

    //开启自动写入时间戳字段
    protected $autoWriteTimestamp = true;

    // 定义时间戳字段名
    protected $createTime = 'detail_create_time';
    protected $updateTime = 'detail_update_time';
    
    // 设置json类型字段
	protected $json = ['detail_extend'];
    
    // 设置JSON数据返回数组
    protected $jsonAssoc = true;

    //多对多 belongsToMany('关联模型名','中间表名','外键名','当前模型关联键名',['模型别名定义'])
    public function type()
    {
        return $this->belongsToMany('Type','TypeMap','type_mp_tid','type_mp_did');
	}

    //一对多
	public function typeMap()
    {
		return $this->hasMany('TypeMap','type_mp_did')->field('type_mp_tid,type_mp_did');
	}

    //多对多
    public function tag()
    {
        return $this->belongsToMany('Tag','TagMap','tag_mp_tid','tag_mp_did');
	}

    //一对多
	public function tagMap()
    {
		return $this->hasMany('TagMap','tag_mp_did')->field('tag_mp_tid,tag_mp_did');
	}

    //一对多
	public function logs()
    {
		return $this->hasMany('Log','log_detail_id','detail_id')->field('log_id,log_detail_id');
	}
}